/* * * * M A P V I S I O N   L I C E N S E  *****************************************************************
         *
         * This MapVision software is © Filip Zavadil 2013. It is licensed under the LGPL license.
         * This MapVision software dynamically links to unmodified Qt5 Library.
         *
         * The Qt5 Library is © 2013 Qt® and/or its subsidiary(-ies), and is licensed under the
         * GNU Lesser General Public License version 2.1 with Qt® LGPL exception version 1.1.
         * Qt5 library is free software; you can redistribute it and/or modify it under the terms of the
         * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
         * Qt5 library is provided “AS IS”, without WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
         * IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
         * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
         *
         * As an additional permission to the GNU Lesser General Public License version 2.1, the object
         * code form of a “work that uses the Library” may incorporate material from a header file that is
         * part of the Library. You may distribute such object code under terms of your choice,
         * provided that: (i) the header files of the Library have not been modified; and (ii)
         * the incorporated material is limited to numerical parameters, data structure layouts, accessors,
         * macros, inline functions and templates; and (iii) you comply with the terms of Section 6 of the
         * GNU Lesser General Public License version 2.1.
         *
         * Moreover, you may apply this exception to a modified version of the Library, provided that such
         * modification does not involve copying material from the Library into the modified Library’s header
         * files unless such material is limited to (i) numerical parameters; (ii) data structure layouts;
         * (iii) accessors; and (iv) small macros, templates and inline functions of five lines or less in length.
         *
         * Furthermore, you are not required to apply this additional permission to a modified version of the Library.
         *
         * You should have received a copy of the GNU Lesser General Public License along with this package;
         * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

         * The source code for Qt 5.X SDK is available from Qt Project here:
         * http://download.qt-project.org/official_releases/qtcreator/2.7/2.7.0/qt-creator-2.7.0-src.zip.
         *
         * ****************************** M A P V I S I O N    S O F T W A R E  ************************************
         *
         * Author:       Filip Zavadil
         * Description:  Software for displaying and exporting map tiles.
         * The sources and executables of MapVision software are available:
         *    - from project hosting on CodePlex.com :   http://mapvision.codeplex.com
         *    - from GIT repositories on Gitorious.org:  https://gitorious.org/mapvision
         * Visit MapVision fanpage on Facebook.com:      https://www.facebook.com/pages/Mapvision/631827753513935
         *
         * *********************************************************************************************************
*/
#ifndef LAYER_H
#define LAYER_H

#include <QtGui>

#include <QtWidgets>
#include "mapview.h"
#include "zavaproj.h"

#include <QtConcurrent/QtConcurrentRun>
#include <QSettings>
#include "dialogpreferencesglobal.h"
#include "listwidget.h"

class Layer : public QDialog
{
   Q_OBJECT

public:
    enum layerType { TMSlocal, WMTSlocal, TMSonline, WMTSonline, MBtiles, GeoImage, UNKNOWN };
    enum RenderingType {AUTO, CONCURRENT, CURRENT};

private:

    layerType type;
    // zValue
    int zValue;
    // name of this layer
    QString layerName;

    QString source;
    // holds the layer visibility value
    bool visible;

    // layer opacity
    qreal opacity;


    QMainWindow * mainWindowPrivate;

    DialogPreferencesGlobal * dialog;

    int id;

    QPointF lonlatOrigin;
    int zoomOrigin;
    int tilesToLoad;


public:
    explicit Layer(QMainWindow *mainWindow);
    ~Layer();

    QGraphicsEffect * effect;
    QGraphicsItemGroup * layerGroup;

    ZavaProj::Yaxis YaxisOrigin;

    QHash<QString,QGraphicsItem*> items;

    QString getLayerName(){return layerName;}
    void setLayerName(QString layerName_){layerName=layerName_;}

    QString getSource(){return source;}
    void setSource(QString source_){source=source_;}

    bool getVisible(){return visible;}
    void setVisible(bool);
    void setVisiblePrivate(bool is){visible = is;}

    int getZvalue(){return zValue;}
    void setZvalue(int zValue_){zValue=zValue_;}

    void changeZvalue(int zVal);

    bool isRendering();

    void sendMessagePublic(QString message){emit sendMessage(message);}

    MapView* getMapView();
    MapScene* getMapScene() {return getMapView()->getScene();}
    ListWidget* getListWidget();

    ZavaProj zavaProj;

    QSettings settings;

    qreal getOpacity(){return opacity;}
    void setOpacity(qreal opacity_){opacity=opacity_;}
    void changeOpacity(qreal opacity_);

    int getId(){return id;}

    QPointF getLonlatOrigin(){return lonlatOrigin;}
    QString getLonlatOriginString(){return zavaProj.lonlat2dms(lonlatOrigin);}
    int getZoomOrigin(){return zoomOrigin;}
    void setOrigin(QPointF lonlat,int zoom){lonlatOrigin=lonlat;zoomOrigin=zoom;}

    // layer type
    layerType getLayerType(){return type;}
    void setLayerType(QString typeString);
    void setLayerType(layerType type_){type=type_;}
    layerType getLayerTypeFromString(QString typeString);
    QString getLayerTypeString(layerType type_);

    RenderingType renderingType;

    // names of sources
    QList<QString> sources;

    void setTilesToLoad(int);



signals:
    void sendMessage(QString);
    void zoomIsChanging(int);
    void layerReady(bool);
    
public slots:
    virtual void mapRectChanged(QRect, int){};
    void zoomChanged(int);
    void sceneHasCleared();
    virtual QImage getTile(QPoint, int){return QImage();}
    void getPreferences();




};

#endif // LAYER_H
